{% extends "risk/risk_base.html" %}
{% block title %}发起放款{% endblock %}
{% block head %}
{{ super() }}
<!--<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-table.min.css') }}">-->
<!--<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>-->
<!--<script src="{{ url_for('static', filename='js/bootstrap-table.min.js') }}"></script>-->
<!--<script src="{{ url_for('static', filename='js/bootstrap-table-zh-CN.min.js') }}"></script>-->
<!--<script src="{{ url_for('static', filename='js/layer.min.js') }}"></script>-->
<style>
    .form-control {
        width: 30%;
    }
    .saw-info-label {
        width: 100px;
    }
    .saw-pic-label {
        width: 100%;
    }
    .saw-info-title {
        background: #F2F2F2;
        padding-top: 7px;
        padding-bottom: 7px;
    }
    
    .pre {display: inline-block;width: 172px;height: 160px;margin: 0 20px 0 0;}
    .pre img {border-radius: 5px;width: 172px;height: 110px;}
    .pre div {color: #3D3D3D;font-size: 13px;width: 170px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
    .pre div > a {float: right;}
    a.pre-del:hover {
        cursor: pointer;
    }

    .saw-upload-pic {
        
    }


</style>

{% endblock %}

{% block page_content %}
<h1 class="page-header">发起放款</h1>
<div>
    <h3 class="saw-info-title">
        对应申请审核流程:
        <a href="/risk/application/detail/{{ ra.id }}">
            {{ flow_id }}
        </a>
        ({{ pledge_type }})
    </h3>
    <div>


    
        <form action="{{ url_for('loan.p_launch')}}" method="post" class="form" id="id-launch-form">
        {% for item in sort_dit %}
        {% set num, title = item %}

            <div class="form-group saw-upload-pic">
                <label class="saw-info-title saw-pic-label">{{ title }}</label>
                <div id="risk_pre{{ num }}" style="width:1000px;">
                    <div id="risk_pic{{ num }}">
                        <a href="javascript:;" class="btn btn-success btn-sm" role="button" id="risk_button{{ num }}">
                        选择文件
                        </a>
                    </div>
                </div>
            </div>
            

            <input type="hidden" name="{{ prefix }}{{ num }}" id="{{ prefix }}{{ num }}" value="">

        
        {% endfor %}
            <input type="hidden" name="pledge_type" value="{{ pledge_type }}">
            <input type="hidden" name="xfrs" value="{{ xfrs }}">
            <input type="hidden" name="flow_id" value="{{ flow_id }}">
            <button class="btn btn-primary">发起</button>
        </form>


    </div>

</div>


{% endblock %}


{% block scripts %}
{{ super() }}
<script src="{{ url_for('static', filename='js/qiniu.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/plupload.full.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.plupload.queue.js') }}"></script>


{% for item in sort_dit %}
{% set num, title = item %}

<script>
var {{ prefix }}{{ num }} = new Array();

var dy_uploader = Qiniu.uploader({
    runtimes: 'html5,flash,html4',      // 上传模式，依次退化
    browse_button: 'risk_button{{ num }}',         // 上传选择的点选按钮，必需
    uptoken_url: '/auth/uptoken/',      // Ajax请求uptoken的Url，强烈建议设置（服务端提供）
    unique_names: false,            // 默认 false，key为文件名。若开启该选项，SDK为自动生成上传成功后的key（文件名）。
    save_key: false,            // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`，则开启，SDK会忽略对key的处理
    filters: {
        mime_types: [{
                title: "Image files", extensions: "jpg,jpeg,png"
        }]
    },
    domain: 'http://omdcfjxex.bkt.clouddn.com/',   //bucket 域名，下载资源时用到，**必需**
    get_new_uptoken: false,         //设置上传文件的时候是否每次都重新获取新的token
    container: 'risk_pic{{ num }}',               //上传区域DOM ID，默认是browser_button的父元素，
    max_file_size: '50mb',              // 最大文件体积限制
    flash_swf_url: '/static/js/Moxie.swf',  //引入flash，相对路径
    max_retries: 1,                     // 上传失败最大重试次数
    dragdrop: true,                     // 开启可拖曳上传
    drop_element: 'risk_pic{{ num }}',            // 拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
    chunk_size: '4mb',                  // 分块上传时，每块的体积
    auto_start: true,                   // 选择文件后自动上传，若关闭需要自己绑定事件触发上传
    init: {
        'FilesAdded': function(up, files) {
            plupload.each(files, function(file) {
            // 文件添加进队列后，处理相关的事情
            });
        },
        'BeforeUpload': function(up, file) {
                // 每个文件上传前，处理相关的事情
                $('#risk_pre{{ num }}').append(
                    '<div class="pre" data-pre-id="' + file.id + '"><img src="{{ url_for('static', filename='img/loading.gif') }}" /><div class="pre-title">Loading</div><div class="pre-info"></div></div>');
            },
        'UploadProgress': function(up, file) {
                    // 每个文件上传时，处理相关的事情
        },
        'FileUploaded': function (up, file, info){
            var info = $.parseJSON(info);
            var domain = up.getOption('domain');
            $('form').append('<input name="photo" type="hidden" data-key="' + info['key'] + '" />');
            $('.pre[data-pre-id="' + file.id + '"]').attr('data-key', info['key']);
            $('.pre[data-pre-id="' + file.id + '"]').children('img').attr('src', domain + info['key'] + '?imageView2/1/w/176/h/110');
            $('.pre[data-pre-id="' + file.id + '"]').children('.pre-title').text(info['key']);
            $('.pre[data-pre-id="' + file.id + '"]').children('.pre-info').html("<span>大小:" + 
            (file.size / 1024).toFixed(1) + " KB</span><a class='pre-del' data-key='" + info['key'] + "'><i class='fa fa-trash'></i> 删除</a>");
            $('.pre-del').bind('click',function () {
                var key = $(this).data('key');
                $('input[data-key="' + key + '"]').remove();
                $('div[data-key="' + key + '"]').remove();
                var index = {{ prefix }}{{ num }}.indexOf(key);
                if (index != -1) {
                        {{ prefix }}{{ num }}.pop(index);
                    }
            })
            {{ prefix }}{{ num }}.push(info['key']);
            $("#{{ prefix }}{{ num }}").val(JSON.stringify({{ prefix }}{{ num }}));
        },
        'Error': function(up, err, errTip) {
            //上传出错时，处理相关的事情
        },
        'UploadComplete': function() {
                //队列文件处理完毕后，处理相关的事情
        },
        'Key': function (up, file) {
                        // 若想在前端对每个文件的key进行个性化处理，可以配置该函数
                        // 该配置必须要在 unique_names: false , save_key: false 时才生效
            ext = Qiniu.getFileExtension(file.name);
            file_name = (new Date()).valueOf();
            var key = file_name + "." + ext;
            // do something with key here
            return key;
        }
    }
});
</script>

{% endfor %}

<script>
$('#id-launch-form').submit( function( e ) {
    e.preventDefault();
    $.ajax( {
      url: "{{ url_for('loan.p_launch')}}" ,
      type: 'POST',
      data: new FormData( this ),
      processData: false,
      contentType: false,
      success: function (r) {
            if (r.success) {
                alert(r.message);
                window.location.href = r.next
            } else {
                alert(r.message);
            }
        }
    } );
    
  } );

</script>


<script>
nav = document.getElementById("nav_flow");
nav.setAttribute("class", "active");
$("#Launch").addClass('in');
$('#launch-loan').css("background", "#E0EEE0");
</script>
{% endblock %}